package com.example.hp.zyfypt411sy.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hp.zyfypt411sy.R;
import com.example.hp.zyfypt411sy.iface.RegisterListener;
import com.example.hp.zyfypt411sy.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
    private TextView tv1,tvzhuce,tvqing,tvname,tvpw,tvqpw;
    private Button btfh,btzc;
    private EditText et1,et2,et3,et4,et5;

    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);

                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }
        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
    }
    private void init() {
        tv1=(TextView)findViewById(R.id.textView5);
        tvzhuce=(TextView)findViewById(R.id.textView6);
        tvname=(TextView)findViewById(R.id.textView8);
        tvpw=(TextView)findViewById(R.id.textView9);
        tvqpw=(TextView)findViewById(R.id.textView10);
        et1=(EditText)findViewById(R.id.editText3);
        et2=(EditText)findViewById(R.id.editText4);
        et3=(EditText)findViewById(R.id.editText5);
        et4=(EditText)findViewById(R.id.editText6);
        et5=(EditText)findViewById(R.id.editText7);
        btfh=(Button)findViewById(R.id.button3);
        btzc=(Button)findViewById(R.id.button4);
        btfh.setOnClickListener(this);
        btzc.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button3:
                finish();
                Intent intent = new Intent();
                intent.setClass(this,LoginActivity.class);//forward为当前activity，forwardTarget为新的activity
                startActivity(intent);
                break;
            case R.id.button4:
                System.out.println("注册——提交");
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(et1.getText().toString(), et2.getText().toString(), et3.getText().toString(), registerListener);
                intent = new Intent(RegisterActivity.this, LoginActivity.class);
                startActivity(intent);
               break;
        }
    }
}
